package com.jidolstar.astro.vo
{
	/**
	 * 시간 단위를 가지는 값을 담는 클래스
	 * @author Yongho, Ji
	 * @since 2009.03.31 
	 */ 	
	public class HMS
	{
		private var isSetHours:Boolean;
		private var isSetHMS:Boolean;
				
		private var _hours:Number;
		private var _hour:int;
		private var _minute:int;
		private var _seconds:Number;
		
		public function HMS( hour:int = 0, minute:int = 0, seconds:Number = 0 ):void
		{
			isSetHours = false;
			isSetHMS = true;
			this._hour = hour;
			this._minute = minute;
			this._seconds = seconds;
		}
		
		public function setHMS( hour:int, minute:int, seconds:Number ):void
		{
			isSetHours = false;
			isSetHMS = true;
			this._hour = hour;
			this._minute = minute;
			this._seconds = seconds;			
		}
		
		public function get hour():int
		{
			if( !isSetHMS ) hours2HMS();
			return _hour;
		}
		
		public function get minute():int
		{
			if( !isSetHMS ) hours2HMS();
			return _minute;
		}
		
		public function get seconds():Number
		{
			if( !isSetHMS ) hours2HMS();
			return _seconds;
		}
		
		public function get hours():Number
		{
			if( !isSetHours )
			{
				isSetHours = true;
				_hours = _hours + _minute/60.0 + _seconds/3600.0;
			}
			return _hours;
		}
		
		public function set hours( value:Number ):void
		{
			if( isNaN( value ) ) 
			{
				throw new ArgumentError( "value is NaN" );
			} 
			isSetHours = true;
			isSetHMS = false;
			_hours = value;
		}
		
		private function hours2HMS():void
		{
			var temp:Number;
			_hour = Math.floor( _hours );
			temp = _hours - _hour;
			temp *= 60.0;
			_minute = Math.floor( temp );
			temp -= _minute;
			temp *= 60.0;
			_seconds = temp;			
		}		
	}
}